package scribble;

import java.awt.*;
import java.awt.event.*;
import java.util.EventListener;
import javax.swing.*;

public class Doodle2 extends Doodle{

//	protected  ScribbleCanvas canvas;
//	protected EventListener listener;
//	protected boolean isApplet = false;
	
	private JTextField textPassword;
	
	
	public Doodle2(boolean isApplet){
		super(isApplet);

		getContentPane().add(makeControlPanel(), BorderLayout.SOUTH);

		
	}
	public Doodle2(){
		//invoked as an applet
		this(true);
	}
	
	protected Component makeControlPanel() {
		
		GridLayout layout = new GridLayout(1, 4);
		
		JPanel controlPanel = new JPanel();
		JButton buttonClear = new JButton("Clear");
		controlPanel.setLayout(layout);
		
		controlPanel.add(buttonClear, layout);
		//controlPanel.add(buttonClear);
		buttonClear.addActionListener(new ClearButtonListener());
		
		controlPanel.add(new JLabel("Password: "), layout);
		//controlPanel.add(new JLabel("Password: "));
		
		
		textPassword = new JTextField("\t\t");
		controlPanel.add(textPassword, layout);
	 	//controlPanel.add(textPassword);
	 	
	 	
	 	JButton buttonGetPass = new JButton("See Password");
		buttonGetPass.addActionListener(new PasswordButtonListener());
		controlPanel.add(buttonGetPass, layout);
		//controlPanel.add(buttonGetPass);
		
		
		return controlPanel;
	}
	
	
	public void init(){
		frameW= 600;
		frameH= 600;
		
		//JFrame frame = new JFrame();
		//this.setTitle("Doodle Password");
		this.getContentPane().setLayout(new BorderLayout());
		this.getContentPane().add(new Doodle2 (), BorderLayout.CENTER);
		//this.addWindowListener(new AppCloser());
		//this.pack();
		//this.setResizable(false);
		//this.setSize(frameW, frameH);
		
		this.show();
	}
	
	class ClearButtonListener implements ActionListener{
		public void actionPerformed(ActionEvent event){
			canvas.clearCanvas();
			password.clearPassword();
			textPassword.setText(password.getPassword());
			canvas.repaint();
		}
	}
	
	class PasswordButtonListener implements ActionListener{
		public void actionPerformed(ActionEvent event){
			textPassword.setText(password.getPassword());
		}
	}
	
	
}
